<%@ include file="/include/taglib.jsp"%>
<c:set var="itemAction" value="View"/>
<html>
<head> 
<title>${modelDisplayName}${' '}${nameInTitle ? fn:escapeXml(item.name) : ''}</title>
</head>
<body>
	<c:choose>
		<c:when test="${item.photosPermitted}">
			<c:set var="buttonText" value="Upload Photos"/>
		</c:when>
		<c:when test="${item.photoPermitted}">
			<c:set var="buttonText" value="Upload Photo"/>
		</c:when>
	</c:choose>
	<c:if test="${item.photosPermitted || item.photoPermitted}">
		<script type="text/javascript">
		function pageinit() {
			$('#${modelName}_${item.id}_photo').uploadify({
			    'swf'      : '/plugin/uploadify/uploadify.swf'
			    , 'uploader' : '/page/item/${modelName}/${modelName}UploadPhoto.jsp'
			    , 'formData'      : {'itemModelName' : '${modelName}', 'itemId' : ${item.id}}
		    	, 'buttonText' : '${buttonText}'
			});
		}
		</script>
	</c:if>
	
	<c:if test="${item.backButton}">
		<div>
			<a  data-inline="true" data-icon="back" data-role="button" href="/page/item/${modelName}/${modelName}Index.jsp">Back to ${fn:escapeXml(item.modelPluralName)}</a>
		</div>
	</c:if>
	<c:choose>
		<c:when test="${item.photosPermitted}">
			<div class="camera_box">
				<div id="camera_index" class="camera_wrap">
					<c:forEach var="photo" items="${item.photos}" varStatus="status">
						<div data-src="${photo.uriPrefix}800${photo.uriSuffix}" data-thumb="${photo.uriPrefix}200${photo.uriSuffix}"></div>
					</c:forEach>
				</div>
			</div>
		</c:when>
		<c:when test="${item.photoPermitted && item.class.name == 'org.computate.model.item.Photo'}">
			<img src="${item.uriPrefix}500${item.uriSuffix}" height="${tate:toInt(item.heightRatio * (item.maxSize gt 500 ? 500 : item.maxSize))}" width="${tate:toInt(item.widthRatio * (item.maxSize gt 500 ? 500 : item.maxSize))}" alt="${fn:escapeXml(item.description)}" />
		</c:when>
		<c:when test="${item.photoPermitted && not empty item.photo}">
			<img src="${item.photo.uriPrefix}500${item.photo.uriSuffix}" height="${tate:toInt(item.photo.heightRatio * (item.photo.maxSize gt 500 ? 500 : item.photo.maxSize))}" width="${tate:toInt(item.photo.widthRatio * (item.photo.maxSize gt 500 ? 500 : item.photo.maxSize))}" alt="${fn:escapeXml(item.photo.description)}" />
		</c:when>
	</c:choose>
	
	<c:if test="${not empty user}">
		<c:if test="${not item.approved}">
			<a href="/page/item/${modelName}/${modelName}Edit.jsp?id=${item.id}&amp;field=approved&amp;value=true&amp;uri=${tate:encodeUri(tate:getRequestUriAndBeyond(pageContext.request))}" data-role="button" data-icon="check" data-inline="true">Approve</a>
		</c:if>
		<c:set var="indexUri" value="/page/item/${modelName}/${modelName}Index.jsp" />
		<a href="/fragment/ItemDelete.jsp?modelName=${fn:escapeXml(modelName)}&amp;modelDisplayName=${fn:escapeXml(item.modelDisplayName)}&amp;name=${tate:encodeUri(item.name)}&amp;id=${item.id}&amp;uri=${tate:encodeUri(indexUri)}" data-rel="dialog" data-transition="slideup" data-role="button" data-icon="delete" data-inline="true">Delete ${fn:escapeXml(modelDisplayName)}</a>
	</c:if>
	<c:set var="item" value="${item}" scope="request"/>
	<c:set var="itemField" value="${itemField}" scope="request"/>
	<jsp:include page="/fragment/Item.jsp"/>
	<c:if test="${not empty user && (item.photosPermitted || item.photoPermitted)}">
		<div class="photos-box">
			<input type="file" id="${modelName}_${item.id}_photo" name="fileData"/>
			<ul data-role="listview" data-split-icon="delete" data-split-theme="d" data-inset="true" class="photos-list">
				<c:forEach var="photo" items="${item.photos}" varStatus="status">
					<li>
						<a href="/page/item/Photo/PhotoView.jsp?id=${photo.id}"> 
							<img src="${photo.uriPrefix}80${photo.uriSuffix}" height="${tate:toInt(photo.heightRatio * (item.photo.maxSize gt 80 ? 80 : item.photo.maxSize))}" width="${tate:toInt(photo.widthRatio * (item.photo.maxSize gt 80 ? 80 : item.photo.maxSize))}" alt="${fn:escapeXml(photo.description)}" />
						</a>
						<a href="/fragment/ItemDelete.jsp?modelName=${fn:escapeXml(photo.modelName)}&amp;modelDisplayName=${fn:escapeXml(photo.modelName)}&amp;name=${fn:escapeXml(photo.name)}&amp;id=${photo.id}&amp;uri=${tate:encodeUri(tate:getRequestUriAndBeyond(pageContext.request))}" data-rel="dialog" data-transition="slideup">Delete Photo</a>
					</li>
				</c:forEach>
			</ul>
		</div>
	</c:if>
</body>
</html>
